package com.wn.class30.service.impl;

import com.wn.class30.entity.Meal;
import com.wn.class30.entity.MealExample;
import com.wn.class30.mapper.MealDao;
import com.wn.class30.service.BackMealService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

@Service
public class BackMealServiceImpl implements BackMealService {
    @Resource
    private MealDao mealDao;
    @Override
    public int selectCount(HashMap map) {
        return (int) mealDao.countByExample(null);
    }

    @Override
    public Object select(HashMap map) {
        MealExample ex = new MealExample();
        Integer page = 0;
        if (!"".equals((String) map.get("page")) && (String) map.get("page") != null) {
            page = Integer.parseInt((String) map.get("page"));
        }
        Integer limit = 0;
        if (!"".equals((String) map.get("limit")) && (String) map.get("limit") != null) {
            limit = Integer.parseInt((String) map.get("limit"));
        }
        ex.setOffset(((long) (page - 1)) * limit);
        ex.setLimit(limit);
        return mealDao.selectByExample(ex);
    }

    @Override
    public void deleteById(Integer mealId) {
        mealDao.deleteByPrimaryKey(mealId);
    }

    @Override
    public void updateMeal(Meal meal) {
        mealDao.updateByPrimaryKey(meal);
    }

    @Override
    public void insertMeal(Meal meal) {
        mealDao.insertSelective(meal);
    }
}
